package com.hxx.utils;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class R {
    private Integer code;//状态码
    private String message;//提示信息
    private Boolean success;//是否成功
    private Map<String, Object> data = new HashMap<>();//返回数据

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    private R(){}
    public static R ok(){
        R r = new R();
        r.setCode(200);
        r.setMessage("成功");
        r.setSuccess(true);
        return r;
    }
    public static R error(){
        R r = new R();
        r.setCode(201);
        r.setMessage("失败");
        r.setSuccess(false);
        return r;
    }
    public R code(Integer code){
        this.setCode(code);
        return this;
    }
    public R message(String message){
        this.setMessage(message);
        return this;
    }
    public R success(Boolean success){
        this.setSuccess(success);
        return this;
    }
    public R data(String key, Object value){
        this.getData().put(key, value);
        return this;
    }
    public R data(Map<String, Object> data){
        this.setData(data);
        return this;
    }
}




















